{% extends 'pages/_base.html' %}
{% from 'tools/card.html' import nonModal %}
{% from 'tools/table.html' import table %}

{% block _base %}

{% set favorite_data = [] %}
{% for row in data.Blog %}
    {% set _ = favorite_data.append({
        'id': '<a href="' ~ url_for("post.get_anyone_page_of_blog", pid=row.id) ~ '">' ~ row.id ~ '</a>',
        'title': row.title,
        'unfavorite':
            '<form action="' ~ url_for("post.post_anyone_service_of_unlike_blog", pid=row.id) ~ '" method="POST" onsubmit="return handleUnfavorite(event, this)">'
            ~ '<button type="submit" class="btn btn-sm btn-warning" style="height: 32px;">取消喜欢</button>'
            ~ '</form>',
    }) %}
{% endfor %}

<script>
function handleUnfavorite(event, form) {
    event.preventDefault();
    const url = form.action;
    fetchPost(url, {}).then(json => {
        flash(json.msg);
    });
}
</script>

{{ nonModal(
    head='<h4>个人喜欢管理</h4>',
    collapse=False,
    body=table(
        required={'id': '帖子ID', 'title': '帖子标题',  'unfavorite': '操作'},
        data=favorite_data
    )
) }}

{% endblock %}